package com.baizhi.wzd.Controller;

import com.baizhi.wzd.Vo.CategoryPageVO;
import com.baizhi.wzd.dto.CommonPageDTO;
import com.baizhi.wzd.entity.Category;
import com.baizhi.wzd.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/category")
@CrossOrigin
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/queryOnePage")
    @ResponseBody
    public CategoryPageVO queryOnePage(@RequestBody CommonPageDTO pageDTO){
        //调业务
        return categoryService.queryOnePage(pageDTO.getPage(), pageDTO.getPageSize());
    }
    //二级类别
    @RequestMapping("/queryTwoPage")
    @ResponseBody
    public CategoryPageVO queryTwoPage(@RequestBody CommonPageDTO pageDTO){
        //调业务
        return categoryService.queryTwoPage(pageDTO.getPage(), pageDTO.getPageSize(),pageDTO.getCategoryId());
    }
    //查询一级类别
    @RequestMapping("/queryByLevelsCategory")
    @ResponseBody
    public List<Category> queryByLevelsCategory(int levels){
        return categoryService.queryByLevelsCategory(levels);
    }
    //添加
    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> register(@RequestBody Category category){
        return categoryService.register(category.getCateName(),category.getParentId());
    }
    //删除
    @RequestMapping("/delete")
    @ResponseBody
    public Map<String,Object> delete(@RequestBody Category category){
        return categoryService.delete(category.getId(),category.getParentId());
    }
    //根据id查询用户信息
    @RequestMapping("/queryById")
    @ResponseBody
    public Category queryById(int id){
        return categoryService.queryById(id);
    }
    //修改
    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(@RequestBody Category category){
        return categoryService.update(category.getId(),category.getCateName(),category.getParentId());
    }
}
